<?php 
@session_start();	
	require_once('execute/inc/config.inc');
	
	$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
						if(!$link) {
							die('Failed to connect to server: ' . mysql_error());
						}
						
						//Select database
						$db = mysql_select_db(DB_DATABASE);
						if(!$db) {
							die("Unable to select database");
						}
	if(isset($_GET['cat_id'])){
	$select_news=mysql_query("SELECT * FROM news where category_id=$_GET[cat_id] order by publish_date desc");
	$qry_date=mysql_query("SELECT max(publish_date) as maxdate from news where category_id=$_GET[cat_id]");
	$row_date = mysql_fetch_array($qry_date);
	$latest_date = date("D, jS F Y - g.i A",strtotime($row_date['maxdate']));
	}
	else{
	$select_news=mysql_query("SELECT * FROM news order by publish_date desc limit 0,6");
	}
	$users=mysql_query("SELECT * FROM perm_members");
	$select_more_news=mysql_query("SELECT * FROM news order by publish_date DESC limit 0,10");
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Recent News</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Le styles -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/bootstrap-responsive.min.css" rel="stylesheet">
    <link href="assets/css/font-awesome.css" rel="stylesheet">
    <style type="text/css">
      body {
        padding-top: 20px;
        padding-bottom: 40px;
      }
    hr {
  border: 0;
  clear:both;
  display:block;
  width: 100%;               
  background-color:#dbdbdb;
  height: 1px;
}
.wordwrap { 
   white-space: pre-wrap;      /* CSS3 */   
   white-space: -moz-pre-wrap; /* Firefox */    
   white-space: -pre-wrap;     /* Opera <7 */   
   white-space: -o-pre-wrap;   /* Opera 7 */    
   word-wrap: break-word;      /* IE */
}
      /* Custom container */
      .container-narrow {
        margin: 0 auto;
        max-width: 900px;
      }
      .container-narrow > hr {
        margin: 30px 0;
      }

      /* Main marketing message and sign up button */
      .jumbotron {
        margin: 60px 0;
        text-align: center;
      }
      .jumbotron h1 {
        font-size: 72px;
        line-height: 1;
      }
      .jumbotron .btn {
        font-size: 21px;
        padding: 14px 24px;
      }

      /* Supporting marketing content */
      .marketing {
        margin: 60px 0;
      }
      .marketing p + h4 {
        margin-top: 28px;
      }
    </style>
    <link href="../assets/css/bootstrap-responsive.css" rel="stylesheet">

    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="../assets/js/html5shiv.js"></script>
    <![endif]-->

   
  </head>

  <body>

    <div class="container">

    <div class="navbar navbar navbar-fixed-top navbar-inverse">
  <div class="navbar-inner">
    <div class="container">
     <ul class="nav">
          <li><a href="index.html"><i class='icon-home'></i>&nbsp;Home</a></li>
          
          <li class='active'><a href="blog.php"><i class='icon-rss'></i>&nbsp;News</a></li>
         
          <li><a href="contact.php"><i class='icon-envelope-alt'></i>&nbsp;Contact</a></li>
        </ul>
        
        <div class="btn-group pull-right" data-toggle="buttons-radio">
		  <a href="login.php" class="btn" >Sign in</a>
		  <a href="signup.php" class="btn btn-danger" data-toggle="tab">Sign up</a>
		  
		</div>
    </div>
  </div>
</div>
   <h2 class='text-info' style='margin-top:43px'><i class="icon-rss"></i> Recent News</h2>
    <?php 
    if(isset($_GET['cat_id'])){
	$cat_head = mysql_query("SELECT * FROM news_categories where id=$_GET[cat_id]");
	if($cat_head){
	$cat_head_row = mysql_fetch_array($cat_head);
	
    ?>
    <h1><?php echo $cat_head_row['name']; ?></h1><p><i>Latest Update - <?php echo $latest_date; ?></i></p>
    <?php
    }
    else{
    	echo mysql_error();
    } 
    }
    else {
    	?>
    	<?php
    }
    ?>
    <hr>
	<div class='row-fluid'>
	<div class="span8">
	<div class="row span12">
    <h3 class="text-info" style="margin-top:-15px;">Top News</h3>
	<?php
	$count=0; 
	while($news_row=mysql_fetch_object($select_news)){
    	$news_id=$news_row->id;
    	$desc=$news_row->desc;
    	$photo_name=$news_row->image;
    	$title=$news_row->title;
    	$text=substr($news_row->content, 0,200);
    	$text.='...';
    	$dt=$news_row->publish_date;
    	$publisher_id=$news_row->publisher_id;
    	$author_select = mysql_query("SELECT * FROM perm_members where id='$publisher_id'");
    	$author_row = mysql_fetch_array($author_select);
    	$author = $author_row['firstname']." ".$author_row['lastname'];
    	$count++;
    ?>
    <div class="span2" <?php if($count==1){ echo "style='margin-left:0;'"; } ?>>
    <a href="details.php?id=<?php echo $news_id; ?>"><img src="uploads/<?php echo $photo_name; ?>" style="margin-bottom:5px; height:100px;" class='span12 img-polaroid'>
    <h6><?php echo $title; ?></h6></a>
    <p class='muted wordwrap' style="margin-top:-10px;"><small><?php echo $desc; ?></small></p>
    </div>
    <?php } ?>
    </div>
    
    <hr>
    <!-- ------------------------------------------ CATEGORIES PART (START)----------------------------------- -->
    
    <div class="row span12" style="margin-left:0; margin-top:-25px;">
    <div class="span6">
      <h3 class="text-info" style="margin-bottom:-20px;">Business</h3>
      <hr>
      <?php 
    $busqry = mysql_query("SELECT * FROM news WHERE category_id = 79 order by publish_date desc limit 0,6");
    $buscount=1;
    while ($busrow= mysql_fetch_array($busqry)){
	if($buscount==1){
    ?>
    <a href="details.php?id=<?php echo $busrow['id']; ?>"><h5 style="margin-top:-15px;"><?php echo $busrow['title']; ?></h5></a>
    <div style="margin-top:-5px;">
    <div class="span6" style="margin-left:0; margin-bottom:5px;"><img src="uploads/<?php echo $busrow['image']; ?>" style="margin-bottom:5px; height:130px;" class='span12 img-polaroid'></div>
    <div class="span6"><p class="wordwrap muted"><?php echo $busrow['desc']; ?></p></div>
    </div>
    <hr>
    <?php } else { ?>
    <a href="details.php?id=<?php echo $busrow['id']; ?>"><h6 style="margin-top:-13px;"><?php echo $busrow['title']; ?></h6></a>
    
    <?php 
    }
	$buscount++;
} ?>
    </div>
    <div class="span6">
    	<h3 class="text-info" style="margin-bottom:-20px;">Technology</h3>
    <hr>
    <?php 
    $busqry = mysql_query("SELECT * FROM news WHERE category_id = 79 order by publish_date desc limit 0,6");
    $buscount=1;
    while ($busrow= mysql_fetch_array($busqry)){
	if($buscount==1){
    ?>
    <a href="details.php?id=<?php echo $busrow['id']; ?>"><h5 style="margin-top:-15px;"><?php echo $busrow['title']; ?></h5></a>
    <div style="margin-top:-5px;">
    <div class="span6" style="margin-left:0; margin-bottom:5px;"><img src="uploads/<?php echo $busrow['image']; ?>" style="margin-bottom:5px; height:130px;" class='span12 img-polaroid'></div>
    <div class="span6"><p class="wordwrap muted"><?php echo $busrow['desc']; ?></p></div>
    </div>
    <hr>
    <?php } else { ?>
    <a href="details.php?id=<?php echo $busrow['id']; ?>"><h6 style="margin-top:-13px;"><?php echo $busrow['title']; ?></h6></a>
    
    <?php 
    }
	$buscount++;
} ?>
    </div>
    <hr>
    <div class="span6" style="margin-left:0; margin-top:-25px;">
      <h3 class="text-info" style="margin-bottom:-20px;">Sports</h3>
    <hr>
    </div>
    <div class="span6">
    	<h3 class="text-info" style="margin-top:-15px; margin-bottom:-20px;">Social</h3>
    	<hr>
    </div>
    </div>
    
        <!-- ------------------------------------------ CATEGORIES PART (FINISH)----------------------------------- -->
    
	</div>
	
	<div class="span4 pull-right">
	<div class="sidebar-nav">
	<div class="well">
		<ul class="nav nav-list">
	
		
		  <li class="nav-header">Categories</li>
		  <?php 
		$cat_select = mysql_query("SELECT * FROM news_categories order by name asc");
		while ($cat_row = mysql_fetch_array($cat_select)){
		$news_qry = mysql_query("SELECT * FROM news where category_id='$cat_row[id]'");
		if (mysql_num_rows($news_qry)>0){
		?>       
          <li><a href="blog.php?cat_id=<?php echo $cat_row['id']; ?>"><i class="icon-tags"></i>&nbsp; <?php echo $cat_row['name']; ?> &nbsp; <span class="badge badge-info"><?php echo mysql_num_rows($news_qry); ?></span></a></li>          
		<?php
		}
		
		}
		?>
		</ul>
	</div>
</div>

<div class="sidebar-nav">
	<div class="well">
		<ul class="nav nav-list"> 
		<li class="nav-header">Latest Update</li> 
		
 
		<li class="divider"></li>
		  <?php 
		  while($row_more_news=mysql_fetch_array($select_more_news)){
		  	
		  	?> 
		  	<li><a href="details.php?id=<?php echo $row_more_news['id'];?>"><i class="icon-bookmark"></i> <?php echo $row_more_news['title']; ?></a></li>
		  <?php 	
		  }
		  ?>
          
		</ul>
	</div>
</div>

<div class="sidebar-nav">
	<div class="well">
		<ul class="nav nav-list"> 
		<li class="nav-header">Archive</li> 
		
 
		<li class="divider"></li>
		  	<li><a href="archive.php"><i class="icon-archive"></i> Archived News</a></li>
		
          
		</ul>
	</div>
</div>
	</div>
	</div>
     
    </div> <!-- /container -->
    <hr>
    <div class="container">	
<div class="row-fluid">
				<div class="span12">
				
				<div class='span5'>
					<address>
						  <strong>TechNation, Afghanistan</strong><br>
						  Shahid Abdul Haq Square 
							Dunya Plaza<br/>
							Ground Floor <br>
						  Kabul, Afghanistan<br>
						  <abbr title="Phone">Phone:</abbr> (+93) (0) 70 616 9995<br/>
						  <abbr title="Email">Email:</abbr> <a href="mailto:info@technation.af">info@technation.af</a><br/>
						</address>
					</div>
					
					
					<div class="span7">
						<h3>Get Social: <a href='#'><i class='icon-facebook-sign'></i></a>&nbsp;<a href='#'><i class='icon-linkedin-sign'></i></a>&nbsp;<a href='#'><i class='icon-twitter-sign'></i></a>&nbsp;<a href='#'><i class='icon-google-plus-sign'></i></a></h3>
						  <h2>Newsletter</h2>
						    
						  <p>Subscribe to our weekly Newsletter and stay tuned.</p>
						    
						 <form class="form-search">
					        <div class="input-append">
					            <input type="text">
					            <button type="submit" class="btn btn-primary">Subscribe Now</button>
					        </div>
					    </form>
						
					</div>
					
					
					
					
					
									
				</div>
			</div>
			<hr>
			<div class="row-fluid">
				<div class="span12">
					<div class="span8">
						<ul class='nav nav-pills'>
						<li><a href="#">Terms of Service</a> </li>   
						<li><a href="#">Privacy</a> </li>   
						<li><a href="#">Security</a></li>
						
						</ul>
					</div>
					<div class="span4">
						<p class="muted pull-right">&copy; 2013 TECHNATION. All rights reserved</p>
					</div>
				</div>
			</div>
  </div>

    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="assets/js/jquery.js"></script>
    <script src="assets/js/bootstrap-transition.js"></script>
    <script src="assets/js/bootstrap-alert.js"></script>
    <script src="assets/js/bootstrap-modal.js"></script>
    <script src="assets/js/bootstrap-dropdown.js"></script>
    <script src="assets/js/bootstrap-scrollspy.js"></script>
    <script src="assets/js/bootstrap-tab.js"></script>
    <script src="assets/js/bootstrap-tooltip.js"></script>
    <script src="assets/js/bootstrap-popover.js"></script>
    <script src="assets/js/bootstrap-button.js"></script>
    <script src="assets/js/bootstrap-collapse.js"></script>
    <script src="assets/js/bootstrap-carousel.js"></script>
    <script src="assets/js/bootstrap-typeahead.js"></script>

  </body>
</html>
